﻿Public Class lab_item_type
    'masmtypergt
    Private lab_item_type_code = Nothing
    Private lab_item_type_name = Nothing
    Private comment = Nothing
    Private wbc_diff = Nothing
    Private selectLabItemType = "SELECT `lab_item_type_code` as 'รหัส lab item', `lab_item_type_name` as 'ชื่อ lab item', `comment` as 'คำอธิบาย lab item', `wbc_diff` as 'wbc diff' FROM lab_item_type"
    'Private selectMasdrgacc = "SELECT DGTYID, DRGTYPE, convert(bit, [STATUS]) FROM MASDRGTYPE"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property lab_item_type_code_() As Integer
        Get
            Return lab_item_type_code
        End Get
        Set(value As Integer)
            lab_item_type_code = value
        End Set
    End Property

    Property lab_item_type_name_() As String
        Get
            Return lab_item_type_name
        End Get
        Set(value As String)
            lab_item_type_name = value
        End Set
    End Property

    Property comment_() As String
        Get
            Return comment
        End Get
        Set(value As String)
            comment = value
        End Set
    End Property

    Property wbc_diff_() As Boolean
        Get
            Return wbc_diff
        End Get
        Set(value As Boolean)
            If value = True Then
                wbc_diff = 1
            Else
                wbc_diff = 0
            End If
        End Set
    End Property

    Property selectLabItemType_() As String
        Get
            Return selectLabItemType
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertLabItemTypeData()
        If TypeOf lab_item_type_name Is String Then
            If connect.GetTable("SELECT lab_item_type_code FROM lab_item_type WHERE lab_item_type_name = '" & lab_item_type_name & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูล lab item นี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    Dim labItemCode As Integer
                    labItemCode = connect.GetTable("SELECT MAX(lab_item_type_code) + 1 FROM lab_item_type").Rows(0)(0)

                    connect.ExecuteNonQuery("INSERT INTO lab_item_type (lab_item_type_code, lab_item_type_name, comment, wbc_diff) VALUES ('" & labItemCode & "', '" & lab_item_type_name & "', '" & comment & "', '" & wbc_diff & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูล lab item เรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editLabItemTypeData()
        If TypeOf lab_item_type_name Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE lab_item_type SET lab_item_type_name = '" & lab_item_type_name & "', comment = '" & comment & "', wbc_diff = '" & wbc_diff & "' WHERE lab_item_type_code = '" & lab_item_type_code & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลกลุ่ม lab เรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class
